package cn.com.xyc.common;

import javax.mail.internet.MimeMessage;

import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.MimeMessageHelper;

public class XuProUtils {

	public static void sendMail(String addressee, String sender,
			JavaMailSender mailSender,String content) {
		try {
			MimeMessage mess = mailSender.createMimeMessage();
			MimeMessageHelper mesHelper = new MimeMessageHelper(mess, true,
					"utf-8");
			mesHelper.setTo(addressee);
			mesHelper.setFrom(sender);
			mesHelper.setSubject("稻草人注册确认邮件");
			mesHelper.setText(getHtml(content), true);
			mailSender.send(mess);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	private static String getHtml(String address) {
		StringBuffer buf = new StringBuffer();
		buf.append("<html>")
				.append("<head>")
				.append("<meta http-equiv='Content-Type' content='text/html; charset=utf-8'/>")
				.append("<link href='http://cdn.bootcss.com/bootstrap/3.3.4/css/bootstrap.min.css' rel='stylesheet'>")
				.append("<script src='http://cdn.bootcss.com/jquery/1.11.2/jquery.min.js'></script>")
				.append("<script src='http://cdn.bootcss.com/bootstrap/3.3.4/js/bootstrap.min.js'></script>")
				.append("</head>")
				.append("<style>")
				.append("body { ")
				.append("padding-top: 70px; ")
				.append("font-family:'Hiragino Sans GB','Microsoft YaHei','微软雅黑',tahoma,arial,simhei,'黑体';")
				.append("background-color:#F7F7F5;")
				.append("}")
				.append("</style>")
				.append("<body>")
				.append("<div class='container'>")
				.append("<div class='col-sm-offset-3 col-sm-7'>")
				.append("<div class='panel panel-default'>")
				.append("<div class='panel-heading' style='background-color:#2BCBEA;'>稻草人联盟</div>")
				.append("<div class='panel-body'>")
				.append("<h2>欢迎加入稻草人联盟！</h1>")
				.append("<h3>点击完成注册：</h2>")
				.append("<a href='"+address+"'>立即激活账号</a>")
				.append("<hr>")
				.append("<p>如果以上按钮无法打开，请把下面的链接复制到浏览器地址栏中打开：</p>")
				.append("<p>http://www.100offer.com/talents/confirmation?confirmation_token=v2hZyknSNKtfkCjLmVX_</p>")
				.append("<hr>	 ").append("</div>").append("</div>")
				.append("</div>").append("</div>").append("</body>")
				.append("</html>");
		return buf.toString();

	}
	public static void main(String[] args) {
		System.out.println(getHtml("http://localhost:8020/XuPro/system/registerPage"));
	}
}
